<?php


namespace app\common\model;


use app\common\model\Admin as adminModel;

class Admin extends BaseModel
{
    public function __construct(array $data = [])
    {
        parent::__construct($data);
    }

    // 管理员所在组
    public function authGroup()
    {
        return $this->belongsTo(AuthGroup::class);
    }

    // 管理员发表的文章
    public function archives()
    {
        return $this->hasMany(Archives::class);
    }

    // 管理员登录日志
    public function adminLog()
    {
        return $this->hasMany(AdminLog::class);
    }

    public function admin()
    {
        return $this->belongsTo(adminModel::class);
    }
    
    public function diggings()
    {
        return $this->belongsTo(Diggings::class);
    }
    
    public function getTotalCountAttr($value,$data)
    {
        $list_all = Project::where('salesman_id',$data['id'])
            ->where('add_type',-1)->select();
        $all_count = count($list_all);
        $add_count = 0;
        $order_count = 0;
        foreach ($list_all as $item) {
            if ($item['is_add'] == 1) $add_count ++;
            if ($item['is_order'] == 1) $order_count ++;
        }
        return [
            "all_count" => $all_count,
            "add_count" => $add_count,
            "order_count" => $order_count,
            "add_lv" => $all_count > 0 ? round($add_count/$all_count*100,2) : 0,
            "order_lv" => $all_count > 0 ? round($order_count/$all_count*100,2) : 0,
        ];
    }
}